/*
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tal.drivechain.chain;

import java.util.HashMap;
import tal.drivechain.parsing.Tokenizer;
import tal.drivechain.plugin.Logger;

/**
 *
 * @author eisental
 */
public abstract class ChainController extends Logger {
    protected HashMap<String, String> properties = new HashMap<String, String>();

    public abstract void takeOver();

    public void parseProperties(String arg) throws IllegalArgumentException {
        if (arg==null || arg.trim().length()==0) return;
        Tokenizer tokenizer = new Tokenizer(arg, ';');
        if (tokenizer.countTokens()==1)
            tokenizer = new Tokenizer(arg, '^');

        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            Tokenizer propTokenizer = new Tokenizer(token, ':');
            if (propTokenizer.countTokens()!=2)
                throw new IllegalArgumentException("Invalid controller property syntax: '" + token + "'");
            properties.put(propTokenizer.getTokens()[0].trim(), propTokenizer.getTokens()[1].trim());
        }
    }

}
